package com.zsc.wxapp.config;

import com.zsc.wxapp.properties.MinIOProperty;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@Slf4j
public class MinIOConfig {

    @Resource
    private MinIOProperty minioProperty;

    /**
     * 初始化minio配置
     */
    @Bean
    @ConditionalOnMissingBean
    public MinioClient minioClient() {

        log.info("minioClient初始化加载:{}", minioProperty);

        return MinioClient.builder()
                .endpoint(minioProperty.getEndpoint()) //操作MinIO地址
                .credentials(minioProperty.getAccessKey(), minioProperty.getSecretKey())
                .build();
    }
}
